package player

import (
	"GameServer/Common/utils"
	"GameServer/Game/errors"
	"GameServer/Game/lib"
	"GameServer/Game/sp"
)

// 8690 圣诞树信息
func (p *Player) ChristmasTreeInfoRequest(req *sp.ChristmasTreeInfoRequest) (res *sp.ChristmasTreeInfoResponse) {
	us := p.User
	uChristmasTree := lib.GetChristmasTree(us)

	res = &sp.ChristmasTreeInfoResponse{
		Tree: lib.FormatChristmasTree(uChristmasTree),
	}
	return
}

// 8691 圣诞树 有等级完成道具，通知客户端 s-c
func (p *Player) christmasNotice() {

	req := &sp.ChatNoticeRequest{}
	p.Send(req)
	return
}

// 8692 圣诞树 领取奖励
func (p *Player) ChristmasRewardRequest(req *sp.ChristmasRewardRequest) (res *sp.ChristmasRewardResponse) {
	us := p.User

	uChristmasTree, uProp, resGoods, boxRes, err := lib.GetChristmasReward("ChristmasRewardRequest", us, req.Level, p.Send)
	if err != nil {
		res = &sp.ChristmasRewardResponse{
			Errcode: errors.ErrCode(err),
		}
		return
	}

	res = &sp.ChristmasRewardResponse{
		Res:    lib.FormatGoodsInfoSps(resGoods),
		BoxRes: lib.FormatBoxResSps(boxRes),
		Tree:   lib.FormatChristmasTree(uChristmasTree),
	}

	p.TimelyUpdateProp(req.GetType(), uProp)
	utils.AsyncFunc(func() {
		p.UpdateProp(req.GetType(), uProp)
	})
	return
}
